package com.java.yz.day11.ketang;
import java.util.Comparator;
import java.util.Scanner;
import java.util.TreeSet;
/*
键盘录入5个学生信息(姓名,语文成绩,数学成绩,英语成绩),按照总分从高到低输出到控制台
 */
class Student7{
    private String name;
    private int chinese;
    private int math;
    private int english;
    public Student7() {
    }
    public Student7(String name, int chinese, int math, int english) {
        this.name = name;
        this.chinese = chinese;
        this.math = math;
        this.english = english;
    }
    public String getName() {
        return name;
    }
    public void setName(String name) {
        this.name = name;
    }
    public int getChinese() {
        return chinese;
    }
    public void setChinese(int chinese) {
        this.chinese = chinese;
    }
    public int getMath() {
        return math;
    }
    public void setMath(int math) {
        this.math = math;
    }
    public int getEnglish() {
        return english;
    }
    public void setEnglish(int english) {
        this.english = english;
    }
    public int getSum(){
        return getChinese()+getEnglish()+getMath();
    }
    @Override
    public String toString() {
        return "Student7{" +
                "name='" + name + '\'' +
                ", chinese=" + chinese +
                ", math=" + math +
                ", english=" + english +
                '}';
    }
}
public class TreeSetText1 {
    public static void main(String[] args) {
        //键盘录入5个学生信息(姓名,语文成绩,数学成绩,英语成绩),按照总分从高到低输出到控制台
        Scanner scanner = new Scanner(System.in);
        TreeSet<Student7> student7s = new TreeSet<>(new Comparator<Student7>() {
            @Override
            public int compare(Student7 o1, Student7 o2) {
                //主要条件：从高到低开始排序
                int i1 = o2.getSum()-o1.getSum();
                //如果总分相同，语文不一样，语文高的在前面
                int i2 = (i1==0)? o2.getChinese()- o1.getChinese() :i1;
                //如果语文分也相同，则比较数学
                int i3 = (i2==0)? o2.getMath() - o1.getMath():i2;
                //如果分都相同，则比较姓名
                int i4 = (i3==0) ? o2.getName().compareTo(o1.getName()):i3;
                return i4;
            }
        });
        for (int i = 1; i <=5; i++) {
            System.out.println("----请输入第"+i+"同学的信息----");
            System.out.print("姓名：");
            String name = scanner.next();
            System.out.print("语文成绩：");
            int i1 = scanner.nextInt();
            System.out.print("数学成绩：");
            int i2 = scanner.nextInt();
            System.out.print("英语成绩：");
            int i3 = scanner.nextInt();
            student7s.add(new Student7(name,i1,i2,i3));
        }
        System.out.println("-----学生成绩如下：-----");
        for (Student7 student7 : student7s) {
            System.out.println("姓名为："+student7.getName()+"语文成绩:"+student7.getChinese()
                    +"数学成绩："+student7.getMath()+"英语成绩："+student7.getEnglish()+"总分成绩为："+student7.getSum());
        }
    }
}
